<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg7.php" ?>
<?php include "ewmysql7.php" ?>
<?php include "phpfn7.php" ?>
<?php include "psacar_pageinfo.php" ?>
<?php include "psacar_userinfo.php" ?>
<?php include "userfn7.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Create page object
$psacar_page_add = new cpsacar_page_add();
$Page =& $psacar_page_add;

// Page init
$psacar_page_add->Page_Init();

// Page main
$psacar_page_add->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--

// Create page object
var psacar_page_add = new ew_Page("psacar_page_add");

// page properties
psacar_page_add.PageID = "add"; // page ID
psacar_page_add.FormID = "fpsacar_pageadd"; // form ID
var EW_PAGE_ID = psacar_page_add.PageID; // for backward compatibility

// extend page with ValidateForm function
psacar_page_add.ValidateForm = function(fobj) {
	ew_PostAutoSuggest(fobj);
	if (!this.ValidateRequired)
		return true; // ignore validation
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
            infix = (fobj.key_count) ? String(i+1) : "";
            elm = fobj.elements["x" + infix + "_category_id"];
            if (elm && !ew_HasValue(elm))
                return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_page->category_id->FldCaption()) ?>");
            
		elm = fobj.elements["x" + infix + "_created_date"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_page->created_date->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_modified_date"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_page->modified_date->FldErrMsg()) ?>");

		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
	}
	return true;
}

// extend page with Form_CustomValidate function
psacar_page_add.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
<?php if (EW_CLIENT_VALIDATE) { ?>
psacar_page_add.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
psacar_page_add.ValidateRequired = false; // no JavaScript validation
<?php } ?>

//-->
</script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
<!--
_width_multiplier = 20;
_height_multiplier = 60;
var ew_DHTMLEditors = [];

// update value from editor to textarea
function ew_UpdateTextArea() {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {			
		var inst;			
		for (inst in CKEDITOR.instances)
			CKEDITOR.instances[inst].updateElement();
	}
}

// update value from textarea to editor
function ew_UpdateDHTMLEditor(name) {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
		var inst = CKEDITOR.instances[name];		
		if (inst)
			inst.setData(inst.element.value);
	}
}

// focus editor
function ew_FocusDHTMLEditor(name) {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
		var inst = CKEDITOR.instances[name];	
		if (inst)
			inst.focus();
	}
}

//-->
</script>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-cold-1.css" title="win2k-1">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<p><span class="phpmaker"><?php echo $Language->Phrase("Add") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $psacar_page->TableCaption() ?><br><br>
<a href="<?php echo $psacar_page->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$psacar_page_add->ShowMessage();
?>
<form name="fpsacar_pageadd" id="fpsacar_pageadd" action="<?php echo ew_CurrentPage() ?>" method="post" onsubmit="return psacar_page_add.ValidateForm(this);">
<p>
<input type="hidden" name="t" id="t" value="psacar_page">
<input type="hidden" name="a_add" id="a_add" value="A">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($psacar_page->category_id->Visible) { // category_id ?>
    <tr<?php echo $psacar_page->category_id->RowAttributes ?>>
        <td class="ewTableHeader"><?php echo $psacar_page->category_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
        <td<?php echo $psacar_page->category_id->CellAttributes() ?>><span id="el_category_id">
                <select id="x_category_id" name="x_category_id" title="<?php echo $psacar_page->category_id->FldTitle() ?>"<?php echo $psacar_page->category_id->EditAttributes() ?>>
                    <?php
                    if (is_array($psacar_page->category_id->EditValue)) {
                        $arwrk = $psacar_page->category_id->EditValue;
                        $rowswrk = count($arwrk);
                        $emptywrk = TRUE;
                        for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                            $selwrk = (strval($psacar_page->category_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                            if ($selwrk <> "")
                                $emptywrk = FALSE;
                            ?>
                            <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                <?php echo $arwrk[$rowcntwrk][1] ?>
                            </option>
                            <?php
                        }
                    }
                    ?>
                </select>
            </span><?php echo $psacar_page->category_id->CustomMsg ?></td>
    </tr>
<?php } ?>    
<?php if ($psacar_page->title->Visible) { // title ?>
	<tr<?php echo $psacar_page->title->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_page->title->FldCaption() ?></td>
		<td<?php echo $psacar_page->title->CellAttributes() ?>><span id="el_title">
<input type="text" name="x_title" id="x_title" title="<?php echo $psacar_page->title->FldTitle() ?>" size="30" maxlength="45" value="<?php echo $psacar_page->title->EditValue ?>"<?php echo $psacar_page->title->EditAttributes() ?>>
</span><?php echo $psacar_page->title->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_page->name->Visible) { // name ?>
	<tr<?php echo $psacar_page->name->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_page->name->FldCaption() ?></td>
		<td<?php echo $psacar_page->name->CellAttributes() ?>><span id="el_name">
<input type="text" name="x_name" id="x_name" title="<?php echo $psacar_page->name->FldTitle() ?>" size="30" maxlength="45" value="<?php echo $psacar_page->name->EditValue ?>"<?php echo $psacar_page->name->EditAttributes() ?>>
</span><?php echo $psacar_page->name->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_page->keyword->Visible) { // keyword ?>
	<tr<?php echo $psacar_page->keyword->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_page->keyword->FldCaption() ?></td>
		<td<?php echo $psacar_page->keyword->CellAttributes() ?>><span id="el_keyword">
<input type="text" name="x_keyword" id="x_keyword" title="<?php echo $psacar_page->keyword->FldTitle() ?>" size="30" maxlength="50" value="<?php echo $psacar_page->keyword->EditValue ?>"<?php echo $psacar_page->keyword->EditAttributes() ?>>
</span><?php echo $psacar_page->keyword->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_page->short_description->Visible) { // short_description ?>
	<tr<?php echo $psacar_page->short_description->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_page->short_description->FldCaption() ?></td>
		<td<?php echo $psacar_page->short_description->CellAttributes() ?>><span id="el_short_description">
<input type="text" name="x_short_description" id="x_short_description" title="<?php echo $psacar_page->short_description->FldTitle() ?>" size="30" maxlength="255" value="<?php echo $psacar_page->short_description->EditValue ?>"<?php echo $psacar_page->short_description->EditAttributes() ?>>
</span><?php echo $psacar_page->short_description->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_page->description->Visible) { // description ?>
	<tr<?php echo $psacar_page->description->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_page->description->FldCaption() ?></td>
		<td<?php echo $psacar_page->description->CellAttributes() ?>><span id="el_description">
<textarea name="x_description" id="x_description" title="<?php echo $psacar_page->description->FldTitle() ?>" cols="40" rows="10"<?php echo $psacar_page->description->EditAttributes() ?>><?php echo $psacar_page->description->EditValue ?></textarea>
<script type="text/javascript">
<!--
ew_DHTMLEditors.push(new ew_DHTMLEditor("x_description", function() {
	var oCKeditor = CKEDITOR.replace('x_description', { width: 40*_width_multiplier, height: 10*_height_multiplier, autoUpdateElement: false, baseHref: 'ckeditor/'});
	this.active = true;
}));
-->
</script>
</span><?php echo $psacar_page->description->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_page->show_menu->Visible) { // show_menu ?>
	<tr<?php echo $psacar_page->show_menu->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_page->show_menu->FldCaption() ?></td>
		<td<?php echo $psacar_page->show_menu->CellAttributes() ?>><span id="el_show_menu">
<div id="tp_x_show_menu" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME; ?>"><input type="checkbox" name="x_show_menu[]" id="x_show_menu[]" title="<?php echo $psacar_page->show_menu->FldTitle() ?>" value="{value}"<?php echo $psacar_page->show_menu->EditAttributes() ?>></div>
<div id="dsl_x_show_menu" repeatcolumn="5">
<?php
$arwrk = $psacar_page->show_menu->EditValue;
if (is_array($arwrk)) {
	$armultiwrk= explode(",", strval($psacar_page->show_menu->CurrentValue));
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = "";
		for ($ari = 0; $ari < count($armultiwrk); $ari++) {
			if (strval($arwrk[$rowcntwrk][0]) == trim(strval($armultiwrk[$ari]))) {
				$selwrk = " checked=\"checked\"";
				if ($selwrk <> "") $emptywrk = FALSE;
				break;
			}
		}

		// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="checkbox" name="x_show_menu[]" id="x_show_menu[]" title="<?php echo $psacar_page->show_menu->FldTitle() ?>" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $psacar_page->show_menu->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</div>
</span><?php echo $psacar_page->show_menu->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_page->is_show->Visible) { // is_show ?>
	<tr<?php echo $psacar_page->is_show->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_page->is_show->FldCaption() ?></td>
		<td<?php echo $psacar_page->is_show->CellAttributes() ?>><span id="el_is_show">
<div id="tp_x_is_show" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME; ?>"><input type="checkbox" name="x_is_show[]" id="x_is_show[]" title="<?php echo $psacar_page->is_show->FldTitle() ?>" value="{value}"<?php echo $psacar_page->is_show->EditAttributes() ?>></div>
<div id="dsl_x_is_show" repeatcolumn="5">
<?php
$arwrk = $psacar_page->is_show->EditValue;
if (is_array($arwrk)) {
	$armultiwrk= explode(",", strval($psacar_page->is_show->CurrentValue));
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = "";
		for ($ari = 0; $ari < count($armultiwrk); $ari++) {
			if (strval($arwrk[$rowcntwrk][0]) == trim(strval($armultiwrk[$ari]))) {
				$selwrk = " checked=\"checked\"";
				if ($selwrk <> "") $emptywrk = FALSE;
				break;
			}
		}

		// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="checkbox" name="x_is_show[]" id="x_is_show[]" title="<?php echo $psacar_page->is_show->FldTitle() ?>" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $psacar_page->is_show->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</div>
</span><?php echo $psacar_page->is_show->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_page->created_date->Visible) { // created_date ?>
	<tr<?php echo $psacar_page->created_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_page->created_date->FldCaption() ?></td>
		<td<?php echo $psacar_page->created_date->CellAttributes() ?>><span id="el_created_date">
<input type="text" name="x_created_date" id="x_created_date" title="<?php echo $psacar_page->created_date->FldTitle() ?>" value="<?php echo $psacar_page->created_date->EditValue ?>"<?php echo $psacar_page->created_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_created_date" name="cal_x_created_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_created_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_created_date" // button id
});
</script>
</span><?php echo $psacar_page->created_date->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_page->modified_date->Visible) { // modified_date ?>
	<tr<?php echo $psacar_page->modified_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_page->modified_date->FldCaption() ?></td>
		<td<?php echo $psacar_page->modified_date->CellAttributes() ?>><span id="el_modified_date">
<input type="text" name="x_modified_date" id="x_modified_date" title="<?php echo $psacar_page->modified_date->FldTitle() ?>" value="<?php echo $psacar_page->modified_date->EditValue ?>"<?php echo $psacar_page->modified_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_modified_date" name="cal_x_modified_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_modified_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_modified_date" // button id
});
</script>
</span><?php echo $psacar_page->modified_date->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("AddBtn")) ?>">
</form>
<script type="text/javascript">
<!--
ew_CreateEditor();  // Create DHTML editor(s)

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php
$psacar_page_add->Page_Terminate();
?>
<?php

//
// Page class
//
class cpsacar_page_add {

	// Page ID
	var $PageID = 'add';

	// Table name
	var $TableName = 'psacar_page';

	// Page object name
	var $PageObjName = 'psacar_page_add';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $psacar_page;
		if ($psacar_page->UseTokenInUrl) $PageUrl .= "t=" . $psacar_page->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Page URLs
	var $AddUrl;
	var $EditUrl;
	var $CopyUrl;
	var $DeleteUrl;
	var $ViewUrl;
	var $ListUrl;

	// Export URLs
	var $ExportPrintUrl;
	var $ExportHtmlUrl;
	var $ExportExcelUrl;
	var $ExportWordUrl;
	var $ExportXmlUrl;
	var $ExportCsvUrl;

	// Update URLs
	var $InlineAddUrl;
	var $InlineCopyUrl;
	var $InlineEditUrl;
	var $GridAddUrl;
	var $GridEditUrl;
	var $MultiDeleteUrl;
	var $MultiUpdateUrl;

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
			$_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
		} else {
			$_SESSION[EW_SESSION_MESSAGE] = $v;
		}
	}

	// Show message
	function ShowMessage() {
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage);
		if ($sMessage <> "") { // Message in Session, display
			echo "<p><span class=\"ewMessage\">" . $sMessage . "</span></p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm, $psacar_page;
		if ($psacar_page->UseTokenInUrl) {
			if ($objForm)
				return ($psacar_page->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($psacar_page->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function cpsacar_page_add() {
		global $conn, $Language;

		// Language object
		$Language = new cLanguage();

		// Table object (psacar_page)
		$GLOBALS["psacar_page"] = new cpsacar_page();

		// Table object (psacar_user)
		$GLOBALS['psacar_user'] = new cpsacar_user();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'add', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'psacar_page', TRUE);

		// Start timer
		$GLOBALS["gsTimer"] = new cTimer();

		// Open connection
		$conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
		global $psacar_page;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}

		// Create form object
		$objForm = new cFormObj();

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		$this->Page_Redirecting($url);
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $sDbMasterFilter = "";
	var $sDbDetailFilter = "";
	var $lPriv = 0;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError, $psacar_page;

		// Load key values from QueryString
		$bCopy = TRUE;
		if (@$_GET["id"] != "") {
		  $psacar_page->id->setQueryStringValue($_GET["id"]);
		} else {
		  $bCopy = FALSE;
		}

		// Process form if post back
		if (@$_POST["a_add"] <> "") {
		   $psacar_page->CurrentAction = $_POST["a_add"]; // Get form action
		  $this->LoadFormValues(); // Load form values

			// Validate form
			if (!$this->ValidateForm()) {
				$psacar_page->CurrentAction = "I"; // Form error, reset action
				$this->setMessage($gsFormError);
			}
		} else { // Not post back
		  if ($bCopy) {
		    $psacar_page->CurrentAction = "C"; // Copy record
		  } else {
		    $psacar_page->CurrentAction = "I"; // Display blank record
		    $this->LoadDefaultValues(); // Load default values
		  }
		}

		// Perform action based on action code
		switch ($psacar_page->CurrentAction) {
		  case "I": // Blank record, no action required
				break;
		  case "C": // Copy an existing record
		   if (!$this->LoadRow()) { // Load record based on key
		      $this->setMessage($Language->Phrase("NoRecord")); // No record found
		      $this->Page_Terminate("psacar_pagelist.php"); // No matching record, return to list
		    }
				break;
		  case "A": // ' Add new record
				$psacar_page->SendEmail = TRUE; // Send email on add success
		    if ($this->AddRow()) { // Add successful
		      $this->setMessage($Language->Phrase("AddSuccess")); // Set up success message
					$sReturnUrl = $psacar_page->getReturnUrl();
					$this->Page_Terminate($sReturnUrl); // Clean up and return
		    } else {
		      $this->RestoreFormValues(); // Add failed, restore form values
		    }
		}

		// Render row based on row type
		$psacar_page->RowType = EW_ROWTYPE_ADD;  // Render add type

		// Render row
		$this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm, $psacar_page;

		// Get upload data
	}

	// Load default values
	function LoadDefaultValues() {
		global $psacar_page;
	}

	// Load form values
	function LoadFormValues() {
            // Load from form
            global $objForm, $psacar_page;
            $psacar_page->title->setFormValue($objForm->GetValue("x_title"));
            $psacar_page->name->setFormValue($objForm->GetValue("x_name"));
            $psacar_page->keyword->setFormValue($objForm->GetValue("x_keyword"));
            $psacar_page->short_description->setFormValue($objForm->GetValue("x_short_description"));
            $psacar_page->description->setFormValue($objForm->GetValue("x_description"));
            $psacar_page->show_menu->setFormValue($objForm->GetValue("x_show_menu"));
            $psacar_page->is_show->setFormValue($objForm->GetValue("x_is_show"));
            $psacar_page->created_date->setFormValue($objForm->GetValue("x_created_date"));
            $psacar_page->created_date->CurrentValue = ew_UnFormatDateTime($psacar_page->created_date->CurrentValue, 5);
            $psacar_page->modified_date->setFormValue($objForm->GetValue("x_modified_date"));
            $psacar_page->modified_date->CurrentValue = ew_UnFormatDateTime($psacar_page->modified_date->CurrentValue, 5);
            $psacar_page->id->setFormValue($objForm->GetValue("x_id"));
            $psacar_page->category_id->setFormValue($objForm->GetValue("x_category_id"));
	}

	// Restore form values
	function RestoreFormValues() {
            global $objForm, $psacar_page;
            $psacar_page->id->CurrentValue = $psacar_page->id->FormValue;
            $psacar_page->title->CurrentValue = $psacar_page->title->FormValue;
            $psacar_page->name->CurrentValue = $psacar_page->name->FormValue;
            $psacar_page->keyword->CurrentValue = $psacar_page->keyword->FormValue;
            $psacar_page->short_description->CurrentValue = $psacar_page->short_description->FormValue;
            $psacar_page->description->CurrentValue = $psacar_page->description->FormValue;
            $psacar_page->show_menu->CurrentValue = $psacar_page->show_menu->FormValue;
            $psacar_page->is_show->CurrentValue = $psacar_page->is_show->FormValue;
            $psacar_page->created_date->CurrentValue = $psacar_page->created_date->FormValue;
            $psacar_page->created_date->CurrentValue = ew_UnFormatDateTime($psacar_page->created_date->CurrentValue, 5);
            $psacar_page->modified_date->CurrentValue = $psacar_page->modified_date->FormValue;
            $psacar_page->modified_date->CurrentValue = ew_UnFormatDateTime($psacar_page->modified_date->CurrentValue, 5);
            $psacar_page->category_id->CurrentValue = $psacar_page->category_id->FormValue;
	}

	// Load row based on key values
	function LoadRow() {
            global $conn, $Security, $psacar_page;
            $sFilter = $psacar_page->KeyFilter();

            // Call Row Selecting event
            $psacar_page->Row_Selecting($sFilter);

            // Load SQL based on filter
            $psacar_page->CurrentFilter = $sFilter;
            $sSql = $psacar_page->SQL();
            $res = FALSE;
            $rs = ew_LoadRecordset($sSql);
            if ($rs && !$rs->EOF) {
                    $res = TRUE;
                    $this->LoadRowValues($rs); // Load row values

                    // Call Row Selected event
                    $psacar_page->Row_Selected($rs);
                    $rs->Close();
            }
            return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
            global $conn, $psacar_page;
            $psacar_page->id->setDbValue($rs->fields('id'));
            $psacar_page->parent_id->setDbValue($rs->fields('parent_id'));
            $psacar_page->title->setDbValue($rs->fields('title'));
            $psacar_page->name->setDbValue($rs->fields('name'));
            $psacar_page->keyword->setDbValue($rs->fields('keyword'));
            $psacar_page->short_description->setDbValue($rs->fields('short_description'));
            $psacar_page->description->setDbValue($rs->fields('description'));
            $psacar_page->show_menu->setDbValue($rs->fields('show_menu'));
            $psacar_page->is_show->setDbValue($rs->fields('is_show'));
            $psacar_page->created_date->setDbValue($rs->fields('created_date'));
            $psacar_page->modified_date->setDbValue($rs->fields('modified_date'));
            $psacar_page->category_id->setDbValue($rs->fields('category_id'));
	}

	// Render row values based on field settings
	function RenderRow() {
            global $conn, $Security, $Language, $psacar_page;

            // Initialize URLs
            // Call Row_Rendering event

            $psacar_page->Row_Rendering();

            // Common render codes for all row types
            // title

            $psacar_page->title->CellCssStyle = ""; $psacar_page->title->CellCssClass = "";
            $psacar_page->title->CellAttrs = array(); $psacar_page->title->ViewAttrs = array(); $psacar_page->title->EditAttrs = array();

            // name
            $psacar_page->name->CellCssStyle = ""; $psacar_page->name->CellCssClass = "";
            $psacar_page->name->CellAttrs = array(); $psacar_page->name->ViewAttrs = array(); $psacar_page->name->EditAttrs = array();

            // keyword
            $psacar_page->keyword->CellCssStyle = ""; $psacar_page->keyword->CellCssClass = "";
            $psacar_page->keyword->CellAttrs = array(); $psacar_page->keyword->ViewAttrs = array(); $psacar_page->keyword->EditAttrs = array();

            // short_description
            $psacar_page->short_description->CellCssStyle = ""; $psacar_page->short_description->CellCssClass = "";
            $psacar_page->short_description->CellAttrs = array(); $psacar_page->short_description->ViewAttrs = array(); $psacar_page->short_description->EditAttrs = array();

            // description
            $psacar_page->description->CellCssStyle = ""; $psacar_page->description->CellCssClass = "";
            $psacar_page->description->CellAttrs = array(); $psacar_page->description->ViewAttrs = array(); $psacar_page->description->EditAttrs = array();

            // show_menu
            $psacar_page->show_menu->CellCssStyle = ""; $psacar_page->show_menu->CellCssClass = "";
            $psacar_page->show_menu->CellAttrs = array(); $psacar_page->show_menu->ViewAttrs = array(); $psacar_page->show_menu->EditAttrs = array();

            // is_show
            $psacar_page->is_show->CellCssStyle = ""; $psacar_page->is_show->CellCssClass = "";
            $psacar_page->is_show->CellAttrs = array(); $psacar_page->is_show->ViewAttrs = array(); $psacar_page->is_show->EditAttrs = array();

            // created_date
            $psacar_page->created_date->CellCssStyle = ""; $psacar_page->created_date->CellCssClass = "";
            $psacar_page->created_date->CellAttrs = array(); $psacar_page->created_date->ViewAttrs = array(); $psacar_page->created_date->EditAttrs = array();

            // modified_date
            $psacar_page->modified_date->CellCssStyle = ""; $psacar_page->modified_date->CellCssClass = "";
            $psacar_page->modified_date->CellAttrs = array(); $psacar_page->modified_date->ViewAttrs = array(); $psacar_page->modified_date->EditAttrs = array();

            // category_id
            $psacar_page->category_id->CellCssStyle = ""; $psacar_page->category_id->CellCssClass = "";
            $psacar_page->category_id->CellAttrs = array(); $psacar_page->category_id->ViewAttrs = array(); $psacar_page->category_id->EditAttrs = array();
            
            if ($psacar_page->RowType == EW_ROWTYPE_VIEW) { // View row                    
            } elseif ($psacar_page->RowType == EW_ROWTYPE_ADD) { // Add row

                // title
                $psacar_page->title->EditCustomAttributes = "";
                $psacar_page->title->EditValue = ew_HtmlEncode($psacar_page->title->CurrentValue);

                // name
                $psacar_page->name->EditCustomAttributes = "";
                $psacar_page->name->EditValue = ew_HtmlEncode($psacar_page->name->CurrentValue);

                // keyword
                $psacar_page->keyword->EditCustomAttributes = "";
                $psacar_page->keyword->EditValue = ew_HtmlEncode($psacar_page->keyword->CurrentValue);

                // short_description
                $psacar_page->short_description->EditCustomAttributes = "";
                $psacar_page->short_description->EditValue = ew_HtmlEncode($psacar_page->short_description->CurrentValue);

                // description
                $psacar_page->description->EditCustomAttributes = "";
                $psacar_page->description->EditValue = ew_HtmlEncode($psacar_page->description->CurrentValue);

                // show_menu
                $psacar_page->show_menu->EditCustomAttributes = "";
                $arwrk = array();
                $arwrk[] = array("1", "Show");
                $psacar_page->show_menu->EditValue = $arwrk;

                // is_show
                $psacar_page->is_show->EditCustomAttributes = "";
                $arwrk = array();
                $arwrk[] = array("1", "Show");
                $psacar_page->is_show->EditValue = $arwrk;

                // created_date
                $psacar_page->created_date->EditCustomAttributes = "";
                $psacar_page->created_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_page->created_date->CurrentValue, 5));

                // modified_date
                $psacar_page->modified_date->EditCustomAttributes = "";
                $psacar_page->modified_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_page->modified_date->CurrentValue, 5));
                
                // category_id
                $psacar_page->category_id->EditCustomAttributes = "";
                $sFilterWrk = "";
                $sSqlWrk = "SELECT `id`, `category`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_page_category`";
                $sWhereWrk = "";
                if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "")
                        $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
                }
                if ($sWhereWrk <> "")
                    $sSqlWrk .= " WHERE " . $sWhereWrk;
                $rswrk = $conn->Execute($sSqlWrk);
                $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
                if ($rswrk)
                    $rswrk->Close();
                array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
                $psacar_page->category_id->EditValue = $arwrk;
                
                // category_id
                $psacar_page->category_id->HrefValue = "";
            }

            // Call Row Rendered event
            if ($psacar_page->RowType <> EW_ROWTYPE_AGGREGATEINIT)
                    $psacar_page->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
            global $Language, $gsFormError, $psacar_page;

            // Initialize form error message
            $gsFormError = "";

            // Check if validation required
            if (!EW_SERVER_VALIDATE)
                    return ($gsFormError == "");
            if (!ew_CheckDate($psacar_page->created_date->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_page->created_date->FldErrMsg();
            }
            if (!ew_CheckDate($psacar_page->modified_date->FormValue)) {
                    if ($gsFormError <> "") $gsFormError .= "<br>";
                    $gsFormError .= $psacar_page->modified_date->FldErrMsg();
            }

            // Return validate result
            $ValidateForm = ($gsFormError == "");

            // Call Form_CustomValidate event
            $sFormCustomError = "";
            $ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
            if ($sFormCustomError <> "") {
                    $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
                    $gsFormError .= $sFormCustomError;
            }
            return $ValidateForm;
	}

	// Add record
	function AddRow() {
		global $conn, $Language, $Security, $psacar_page;
		$rsnew = array();

		// title
		$psacar_page->title->SetDbValueDef($rsnew, $psacar_page->title->CurrentValue, NULL, FALSE);

		// name
		$psacar_page->name->SetDbValueDef($rsnew, $psacar_page->name->CurrentValue, NULL, FALSE);

		// keyword
		$psacar_page->keyword->SetDbValueDef($rsnew, $psacar_page->keyword->CurrentValue, NULL, FALSE);

		// short_description
		$psacar_page->short_description->SetDbValueDef($rsnew, $psacar_page->short_description->CurrentValue, NULL, FALSE);

		// description
		$psacar_page->description->SetDbValueDef($rsnew, $psacar_page->description->CurrentValue, NULL, FALSE);

		// show_menu
		$psacar_page->show_menu->SetDbValueDef($rsnew, $psacar_page->show_menu->CurrentValue, NULL, FALSE);

		// is_show
		$psacar_page->is_show->SetDbValueDef($rsnew, $psacar_page->is_show->CurrentValue, NULL, FALSE);

		// created_date
		$psacar_page->created_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_page->created_date->CurrentValue, 5, FALSE), NULL);

		// modified_date
		$psacar_page->modified_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_page->modified_date->CurrentValue, 5, FALSE), NULL);

                // category_id
                $psacar_page->category_id->SetDbValueDef($rsnew, $psacar_page->category_id->CurrentValue, NULL, FALSE);                    
                
		// Call Row Inserting event
		$bInsertRow = $psacar_page->Row_Inserting($rsnew);
		if ($bInsertRow) {
                    $conn->raiseErrorFn = 'ew_ErrorFn';
                    $AddRow = $conn->Execute($psacar_page->InsertSQL($rsnew));
                    $conn->raiseErrorFn = '';
		} else {
                    if ($psacar_page->CancelMessage <> "") {
                        $this->setMessage($psacar_page->CancelMessage);
                        $psacar_page->CancelMessage = "";
                    } else {
                        $this->setMessage($Language->Phrase("InsertCancelled"));
                    }
                    $AddRow = FALSE;
		}
		if ($AddRow) {
                    $psacar_page->id->setDbValue($conn->Insert_ID());
                    $rsnew['id'] = $psacar_page->id->DbValue;

                    // Call Row Inserted event
                    $psacar_page->Row_Inserted($rsnew);
		}
		return $AddRow;
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	function Message_Showing(&$msg) {

		// Example:
		//$msg = "your new message";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
